package com.atguigu.auth.service.impl;

import com.atguigu.auth.mapper.SysDeptMapper;
import com.atguigu.auth.service.SysDeptService;
import com.atguigu.model.system.SysDept;
import com.atguigu.vo.system.SysDeptQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * ClassName: SysDeptServiceImpl
 * Package: com.atguigu.auth.service.impl
 * Description:
 *
 * @Author: 比特张
 * @Create: 2023/9/3 - 0:44
 * @Version: v1.0
 */
@Service
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
    @Override
    public IPage<SysDept> pageQueryDept(Long page, Long limit, SysDeptQueryVo sysDeptQueryVo) {
        Page<SysDept> sysDeptPage = new Page<>(page, limit);

        LambdaQueryWrapper<SysDept> wrapper = new LambdaQueryWrapper<>();
        String keyword = sysDeptQueryVo.getKeyword();

        if (!StringUtils.isEmpty(keyword)) {
            wrapper.like(SysDept::getName, keyword)
                    .or().like(SysDept::getLeader, keyword)
                    .or().eq(SysDept::getPhone, keyword);
        }
        if (!StringUtils.isEmpty(sysDeptQueryVo.getCreateTimeEnd())) {
            //大于等于
            wrapper.ge(SysDept::getCreateTime, sysDeptQueryVo.getCreateTimeEnd());
        }
        if (!StringUtils.isEmpty(sysDeptQueryVo.getCreateTimeBegin())) {
            //小于等于
            wrapper.le(SysDept::getCreateTime, sysDeptQueryVo.getCreateTimeBegin());
        }
        IPage<SysDept> deptPage = page(sysDeptPage, wrapper);
        return deptPage;
    }
}
